<template>
  <div class='left-box flex flex-space-between flex-column hide-scrollbar'>
    <div class="box-title">
      <CustomTitle title="设备汇总" :isAutoMargin="false" :isLine="true" fontSet="font1"></CustomTitle>
    </div>
    <div class="box-content flex flex-space-between hide-scrollbar">
      <div class="box-item flex" v-for="(item, index) in itemGroup" :key="index">
        <div class="item-icon flex flex-bcenter">
          <i class="iconfontShuzhi" :class="'icon-' + item.type"></i>
        </div>
        <div class="item-content flex flex-column both-100">
          <div class="item-title">{{ item.title }}</div>
          <div class="item-content">
            <NumberCard v-model="item.value" :time="1"></NumberCard>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import NumberCard from '@/components/Dashboard/Number';
import { getDeviceType } from '../api'
export default {
  components: {
    NumberCard
  },
  data () {
    return {
      itemGroup: [],
      deviceIconList: {
        '消防设备': 'xiaofangshebei',
        '安防设备': 'yanwutance',
        '智能门禁': 'fangleijiance',
        '智能安防': 'yongdianjiance',
        '编码设备': 'anfangshebei',
        '安防设备': 'anfangshebei',
        '烟雾探测': 'yanwutance',
        '防雷设备': 'yongdianjiance',
        '酒精探测设备': 'jiujingtance',
        '其它设备': 'yongdianjiance',
        '视频监控': 'shipinjiankong'
      }
    }
  },
  computed: {},
  watch: {},
  methods: {
    async getData (deptId) {
      const params = {
        deptId
      }
      const response = await getDeviceType(params)
      try {
        if (response.code === 200) {
          this.itemGroup = []
          this.initDeviceList(response.data)
        }
      } catch (error) {
        console.error(error)
      }
    },
    initDeviceList (data) {
      this.itemGroup = data.map(item => {
        return {
          title: item.deviceType.deviceTypeName,
          value: item.deviceNum,
          type: this.deviceIconList[item.deviceType.deviceTypeName]
        }
      })
      // for (const key in data) {
      //   this.itemGroup.push({
      //     title: key,
      //     value: data[key],
      //     type: this.deviceIconList[key]
      //   })
      // }
    },
    getIconClass (type) {
      const inPreFix = 'icon-'
      const cleanedType = this.cleanInput(type)
      return cleanedType ? inPreFix + cleanedType : inPreFix + 'anfangshebei'
    },
    cleanInput (input) {
      if (typeof input === 'string') {
        return input.trim()
      }
      return undefined
    }
  },
}
</script>

<style lang='less' scoped>
.box-title {
  width: 100%;
}
.box-content {
  height: calc(100% - 40px);
  overflow: auto;
  flex-wrap: wrap;
  align-items: center;
  .box-item {
    width: 50%;
    .item-icon {
      width: 60px;
      height: 60px;
      background: url("@/assets/images/dashboard/box2.png") no-repeat;
    }
    .item-content {
      flex: 1;
      .item-content {
        font-family: Oswald, Oswald;
        font-weight: 500;
        font-size: 20px;
        color: #30dcff;
        background: rgba(143, 171, 191, 0.1);
        padding: 5px;
        box-sizing: border-box;
      }
      .item-title {
        font-family: Source Han Sans CN, Source Han Sans CN;
        font-weight: 400;
        font-size: 14px;
        color: #d9e7ff;
        position: relative;
        &::before {
          content: "";
          position: absolute;
          top: 10px;
          bottom: 0;
          width: 100%;
          height: 6px;
          background: rgba(143, 171, 191, 0.1);
        }
      }
    }
  }
}
</style>